package cn.edu.wynu;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestPropertyInject {
    String name;
    Integer age;

    /**
     * 使用属性注入,本质上是spring去调用实体类的set方法
     * 因此需要提供set方法(可以直接生成alt + insert 选择setter)
     * @param name
     */

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "TestPropertyInject{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public static void main(String[] args) {
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("cats.xml");
        // 传名字进去还需要强转
        Object zrk = context.getBean("zrk");

        // 传类型.class进去返回值就是指定类型,不需要强转
        TestPropertyInject inject = context.getBean(TestPropertyInject.class);

        System.out.println(zrk);
        System.out.println(inject);
    }
}
